package com.frank.wcld.yjda.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.frank.common.annotation.Log;
import com.frank.common.enums.BusinessType;
import com.frank.wcld.yjda.domain.WcldYjda;
import com.frank.wcld.yjda.service.IWcldYjdaService;
import com.frank.common.core.controller.BaseController;
import com.frank.common.core.domain.AjaxResult;
import com.frank.common.utils.poi.ExcelUtil;
import com.frank.common.core.page.TableDataInfo;

/**
 * 业绩档案Controller
 * 
 * @author frank
 * @date 2025-08-30
 */
@Controller
@RequestMapping("/wcld/yjda")
public class WcldYjdaController extends BaseController
{
    private String prefix = "wcld/yjda";

    @Autowired
    private IWcldYjdaService wcldYjdaService;

    @RequiresPermissions("wcld:yjda:view")
    @GetMapping()
    public String yjda()
    {
        return prefix + "/yjda";
    }

    /**
     * 查询业绩档案列表
     */
    @RequiresPermissions("wcld:yjda:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WcldYjda wcldYjda)
    {
        startPage();
        List<WcldYjda> list = wcldYjdaService.selectWcldYjdaList(wcldYjda);
        return getDataTable(list);
    }

    /**
     * 导出业绩档案列表
     */
    @RequiresPermissions("wcld:yjda:export")
    @Log(title = "业绩档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WcldYjda wcldYjda)
    {
        List<WcldYjda> list = wcldYjdaService.selectWcldYjdaList(wcldYjda);
        ExcelUtil<WcldYjda> util = new ExcelUtil<WcldYjda>(WcldYjda.class);
        return util.exportExcel(list, "业绩档案数据");
    }

    /**
     * 新增业绩档案
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存业绩档案
     */
    @RequiresPermissions("wcld:yjda:add")
    @Log(title = "业绩档案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WcldYjda wcldYjda)
    {
        wcldYjda.setCreateBy(getLoginName());
        return toAjax(wcldYjdaService.insertWcldYjda(wcldYjda));
    }

    /**
     * 修改业绩档案
     */
    @RequiresPermissions("wcld:yjda:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WcldYjda wcldYjda = wcldYjdaService.selectWcldYjdaById(id);
        mmap.put("wcldYjda", wcldYjda);
        return prefix + "/edit";
    }

    /**
     * 修改保存业绩档案
     */
    @RequiresPermissions("wcld:yjda:edit")
    @Log(title = "业绩档案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WcldYjda wcldYjda)
    {
        wcldYjda.setUpdateBy(getLoginName());
        return toAjax(wcldYjdaService.updateWcldYjda(wcldYjda));
    }

    /**
     * 删除业绩档案
     */
    @RequiresPermissions("wcld:yjda:remove")
    @Log(title = "业绩档案", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wcldYjdaService.deleteWcldYjdaByIds(ids));
    }
}
